package com.masterclient.app.modules.goods.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.eoner.baselibrary.bean.goods.CommodityDetailData;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.R;
import com.masterclient.app.base.MainViewHolder;
import com.masterclient.app.widget.StaggeredGoodsItemDecoration;
import com.masterclient.app.widget.StaggeredGridNoScrollLayoutManager;

public class CommodityDetailRecommendProductAdapter extends DelegateAdapter.Adapter<MainViewHolder> {

    Activity mContext;

    private LayoutHelper mLayoutHelper;


    private VirtualLayoutManager.LayoutParams mLayoutParams;
    private int mCount = 0;

    CommodityDetailData data;


    public CommodityDetailRecommendProductAdapter(Activity context, LayoutHelper layoutHelper, int count) {
        this(context, layoutHelper, count, null,null);
    }

    public CommodityDetailRecommendProductAdapter(Activity context, LayoutHelper layoutHelper, int count, @NonNull VirtualLayoutManager.LayoutParams layoutParams, CommodityDetailData data) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.mCount = count;
        this.mLayoutParams = layoutParams;
        this.data = data;
    }
    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }
    @Override
    protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {

    }

    @Override
    public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }
    @Override
    public void onBindViewHolder(MainViewHolder holder, int position) {
        if(mLayoutParams!=null) {
            holder.itemView.setLayoutParams(
                    new VirtualLayoutManager.LayoutParams(mLayoutParams));
        }

        RecyclerView recyclerView = holder.itemView.findViewById(R.id.recyclerView);

        StaggeredGridNoScrollLayoutManager layoutManager = new StaggeredGridNoScrollLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(null);

        CommodityRecyclerAdapter commodityRecyclerAdapter = new CommodityRecyclerAdapter();
        commodityRecyclerAdapter.setStrings("商品详情","推荐");
        recyclerView.setAdapter(commodityRecyclerAdapter);
        commodityRecyclerAdapter.bindToRecyclerView(recyclerView);
        recyclerView.addItemDecoration(new StaggeredGoodsItemDecoration(ScreenUtils.dp2px(10)));
        commodityRecyclerAdapter.setNewData(data.getRecommend_products());

    }


    @Override
    public int getItemCount() {
        return mCount;
    }

    @Override
    public int getItemViewType(int position) {
        return 7;
    }
}
